package owg.util.awt;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import owg.util.data.ExternalStore;

public interface ActionSource
	{
	static ExternalStore<ActionSource, ArrayList<ActionListener>> actionListeners = new ExternalStore<ActionSource, ArrayList<ActionListener>>(ActionSource.class, () -> new ArrayList<>());
	
	default void fireEvents(int modifiers)
		{
		ActionEvent e = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "Action: "+getClass().getSimpleName(), System.currentTimeMillis(), modifiers);
		for(ActionListener l : actionListeners.get(this))
			l.actionPerformed(e);
		}
	
	public default void addActionListener(ActionListener l)
		{
		actionListeners.get(this).add(l);
		}
	
	public default boolean removeActionListener(ActionListener l)
		{
		return actionListeners.get(this).remove(l);
		}
	}
